<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver delete_all_cookies method</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
promise_test(async t => {
  document.cookie = "test1=1";
  document.cookie = "test2=2; path=/";
  document.cookie = "test3=3; path=/cookies/resources";

  return test_driver.delete_all_cookies().then(() => {
    assert_true(document.cookie === "");
  });
}, "DOM-set cookies get deleted");

promise_test(async t => {
  const cookie = "test1=1";
  const encoded = encodeURIComponent(cookie);
  await fetch(`/cookies/resources/cookie.py?set=${encoded}`)

  const cookie2 = "test2=2; path=/";
  const encoded2 = encodeURIComponent(cookie2);
  await fetch(`/cookies/resources/cookie.py?set=${encoded2}`)

  const cookie3 = "test3=3; path=/cookies/resources";
  const encoded3 = encodeURIComponent(cookie3);
  await fetch(`/cookies/resources/cookie.py?set=${encoded3}`)

  const cookie4 = "test4=4; HttpOnly";
  const encoded4 = encodeURIComponent(cookie4);
  await fetch(`/cookies/resources/cookie.py?set=${encoded4}`)

  return test_driver.delete_all_cookies().then(() => {
    assert_true(document.cookie === "");
  });
}, "HTTP-set cookies get deleted");
</script>
